/*
 *
 */
package web.models;

import ejb.ProductBeanLocal;
import entities.Product;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Jesus
 */
public class ProductModel extends ListDataModel<Product> implements SelectableDataModel<Product> {

    @EJB
    ProductBeanLocal productBean;

    public ProductModel() {
    }

    public ProductModel(List<Product> products) {
        super(products);
    }

    @Override
    public Object getRowKey(Product product) {
        if (product != null) {
            return product.getId();
        }
        return null;
    }

    @Override
    public Product getRowData(String rowKey) {
        List<Product> products = (List<Product>) getWrappedData();
        for (Product product : products) {
            if (rowKey.equals(product.getId().toString())) {
                return product;
            }
        }
        return null;
    }
}
